﻿using System;
using System.Collections;
using System.Collections.Generic;
using Gameplay.PVE.Survivor;
using OWL.Rendering.HRP;
using UnityEngine;
using UnityEngine.Serialization;
using Yoozoo.HRP.Runtime;

[Serializable]
public class MapObstacleState
{
    [Tooltip("显示上限")]
    public float up;
    [Tooltip("显示下限")]
    public float down;
    public GameObject stateObject;
}

public class HpStateDisplay : MonoBehaviour
{
    public List<MapObstacleState> states;
    public int hitEffect;

    private List<bool> objectValid = new List<bool>();
    public void Init()
    {
        for (int i = 0; i < states.Count; i++)
        {
            objectValid.Add(states[i] != null);
        }
    }
    public void OnHpChange(float hpPercent)
    {
        for (int i = 0; i < states.Count; i++)
        {
            var down = states[i].down;
            var up = states[i].up;
            if (up <= 0)
            {
                down = -0.1f;
            }
            if (hpPercent > down && hpPercent <= up)
            {
                if (objectValid[i])
                {
                    states[i].stateObject.SetActive(true);
                }
                    
            }
            else
            {
                if (objectValid[i])
                {
                    states[i].stateObject.SetActive(false);
                }
            }
        }
    }
    
    
    public void CopyFromObstacle(MapObstacleData mapObstacleData)
    {
        if (mapObstacleData.states != null && mapObstacleData.states.Count > 0)
        {
            states = new List<MapObstacleState>();
            for (int i = 0; i < mapObstacleData.states.Count; i++)
            {
                states.Add(mapObstacleData.states[i]);
            }
        }
        hitEffect = mapObstacleData.hitEffect;
    }
}
